import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsNotEmpty, IsNumber, IsOptional, Max, Min } from 'class-validator';
import { toNumber } from 'lodash';
import { BaseEntity } from 'typeorm';
import { UserEntity } from '../entities';

export class QueryUserDto {
    @Min(1, { message: '当前页数不得小于1' })
    @Transform(({ value }) => toNumber(value))
    @IsNotEmpty({ message: '当前页数不得为空' })
    page: number;

    @Min(1, { message: '当页条数不得小于1' })
    @Max(10, { message: '当页条数不得大于10' })
    @Transform(({ value }) => toNumber(value))
    @IsNotEmpty({ message: '当页条数不得为空' })
    pageSize: number;

    @IsOptional({ always: true })
    username?: string;

    @IsOptional({ always: true })
    nickname?: string;

    @IsOptional({ always: true })
    email?: string;
}

export class PaginteReturnDto {
    @ApiProperty()
    totalCount: number;

    @ApiProperty({ type: () => UserEntity, description: 'User who created the post' })
    users: UserEntity[];
}
